home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / g_quake / pixel.zip / WEAPONS.QC < prev   
Text File  |  1996-08-04  |  25KB  |  1,223 lines

  1. /*
  2. */
  3. void (entity targ, entity inflictor, entity attacker, float damage) T_Damage;
  4. void () player_run;
  5. void(entity bomb, entity attacker, float rad, entity ignore) T_RadiusDamage;
  6. void(vector org, vector vel, float damage) SpawnBlood;
  7. void() SuperDamageSound;
  8.  
  9.  
  10. // called by worldspawn
  11. void() W_Precache =
  12. {
  13.     precache_sound ("weapons/r_exp3.wav");    // new rocket explosion
  14.     precache_sound ("weapons/rocket1i.wav");    // spike gun
  15.     precache_sound ("weapons/sgun1.wav");
  16.     precache_sound ("weapons/guncock.wav");    // player shotgun
  17.     precache_sound ("weapons/ric1.wav");    // ricochet (used in c code)
  18.     precache_sound ("weapons/ric2.wav");    // ricochet (used in c code)
  19.     precache_sound ("weapons/ric3.wav");    // ricochet (used in c code)
  20.     precache_sound ("weapons/spike2.wav");    // super spikes
  21.     precache_sound ("weapons/tink1.wav");    // spikes tink (used in c code)
  22.     precache_sound ("weapons/grenade.wav");    // grenade launcher
  23.     precache_sound ("weapons/bounce.wav");        // grenade bounce
  24.     precache_sound ("weapons/shotgn2.wav");    // super shotgun
  25. };
  26.  
  27. float() crandom =
  28. {
  29.     return 2*(random() - 0.5);
  30. };
  31.  
  32. /*
  33. ================
  34. W_FireAxe
  35. ================
  36. */
  37. void() W_FireAxe =
  38. {
  39.     local    vector    source;
  40.     local    vector    org;
  41.  
  42.     source = self.origin + '0 0 16';
  43.     traceline (source, source + v_forward*64, FALSE, self);
  44.     if (trace_fraction == 1.0)
  45.         return;
  46.     
  47.     org = trace_endpos - v_forward*4;
  48.  
  49.     if (trace_ent.takedamage)
  50.     {
  51.         trace_ent.axhitme = 1;
  52.         SpawnBlood (org, '0 0 0', 20);
  53.         T_Damage (trace_ent, self, self, 20);
  54.     }
  55.     else
  56.     {    // hit wall
  57.         sound (self, CHAN_WEAPON, "player/axhit2.wav", 1, ATTN_NORM);
  58.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  59.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  60.         WriteCoord (MSG_BROADCAST, org_x);
  61.         WriteCoord (MSG_BROADCAST, org_y);
  62.         WriteCoord (MSG_BROADCAST, org_z);
  63.     }
  64. };
  65.  
  66.  
  67. //============================================================================
  68.  
  69.  
  70. vector() wall_velocity =
  71. {
  72.     local vector    vel;
  73.     
  74.     vel = normalize (self.velocity);
  75.     vel = normalize(vel + v_up*(random()- 0.5) + v_right*(random()- 0.5));
  76.     vel = vel + 2*trace_plane_normal;
  77.     vel = vel * 200;
  78.     
  79.     return vel;
  80. };
  81.  
  82.  
  83. /*
  84. ================
  85. SpawnMeatSpray
  86. ================
  87. */
  88. void(vector org, vector vel) SpawnMeatSpray =
  89. {
  90.     local    entity missile, mpuff;
  91.     local    vector    org;
  92.  
  93.     missile = spawn ();
  94.     missile.owner = self;
  95.     missile.movetype = MOVETYPE_BOUNCE;
  96.     missile.solid = SOLID_NOT;
  97.  
  98.     makevectors (self.angles);
  99.  
  100.     missile.velocity = vel;
  101.     missile.velocity_z = missile.velocity_z + 250 + 50*random();
  102.  
  103.     missile.avelocity = '3000 1000 2000';
  104.     
  105. // set missile duration
  106.     missile.nextthink = time + 1;
  107.     missile.think = SUB_Remove;
  108.  
  109.     setmodel (missile, "progs/zom_gib.mdl");
  110.     setsize (missile, '0 0 0', '0 0 0');        
  111.     setorigin (missile, org);
  112. };
  113.  
  114. /*
  115. ================
  116. SpawnBlood
  117. ================
  118. */
  119. void(vector org, vector vel, float damage) SpawnBlood =
  120. {
  121.     particle (org, vel*0.1, 73, damage*2);
  122. };
  123.  
  124. /*
  125. ================
  126. spawn_touchblood
  127. ================
  128. */
  129. void(float damage) spawn_touchblood =
  130. {
  131.     local vector    vel;
  132.  
  133.     vel = wall_velocity () * 0.2;
  134.     SpawnBlood (self.origin + vel*0.01, vel, damage);
  135. };
  136.  
  137.  
  138. /*
  139. ================
  140. SpawnChunk
  141. ================
  142. */
  143. void(vector org, vector vel) SpawnChunk =
  144. {
  145.     particle (org, vel*0.02, 0, 10);
  146. };
  147.  
  148. /*
  149. ==============================================================================
  150.  
  151. MULTI-DAMAGE
  152.  
  153. Collects multiple small damages into a single damage
  154.  
  155. ==============================================================================
  156. */
  157.  
  158. entity    multi_ent;
  159. float    multi_damage;
  160.  
  161. void() ClearMultiDamage =
  162. {
  163.     multi_ent = world;
  164.     multi_damage = 0;
  165. };
  166.  
  167. void() ApplyMultiDamage =
  168. {
  169.     if (!multi_ent)
  170.         return;
  171.     T_Damage (multi_ent, self, self, multi_damage);
  172. };
  173.  
  174. void(entity hit, float damage) AddMultiDamage =
  175. {
  176.     if (!hit)
  177.         return;
  178.     
  179.     if (hit != multi_ent)
  180.     {
  181.         ApplyMultiDamage ();
  182.         multi_damage = damage;
  183.         multi_ent = hit;
  184.     }
  185.     else
  186.         multi_damage = multi_damage + damage;
  187. };
  188.  
  189. /*
  190. ==============================================================================
  191.  
  192. BULLETS
  193.  
  194. ==============================================================================
  195. */
  196.  
  197. /*
  198. ================
  199. TraceAttack
  200. ================
  201. */
  202. void(float damage, vector dir) TraceAttack =
  203. {
  204.     local    vector    vel, org;
  205.     
  206.     vel = normalize(dir + v_up*crandom() + v_right*crandom());
  207.     vel = vel + 2*trace_plane_normal;
  208.     vel = vel * 200;
  209.  
  210.     org = trace_endpos - dir*4;
  211.  
  212.     if (trace_ent.takedamage)
  213.     {
  214.         SpawnBlood (org, vel*0.2, damage);
  215.         AddMultiDamage (trace_ent, damage);
  216.     }
  217.     else
  218.     {
  219.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  220.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  221.         WriteCoord (MSG_BROADCAST, org_x);
  222.         WriteCoord (MSG_BROADCAST, org_y);
  223.         WriteCoord (MSG_BROADCAST, org_z);
  224.     }
  225. };
  226.  
  227. /*
  228. ================
  229. FireBullets
  230.  
  231. Used by shotgun, super shotgun, and enemy soldier firing
  232. Go to the trouble of combining multiple pellets into a single damage call.
  233. ================
  234. */
  235. void(float shotcount, vector dir, vector spread) FireBullets =
  236. {
  237.     local    vector direction;
  238.     local    vector    src;
  239.     
  240.     makevectors(self.v_angle);
  241.  
  242.     src = self.origin + v_forward*10;
  243.     src_z = self.absmin_z + self.size_z * 0.7;
  244.  
  245.     ClearMultiDamage ();
  246.     while (shotcount > 0)
  247.     {
  248.         direction = dir + crandom()*spread_x*v_right + crandom()*spread_y*v_up;
  249.  
  250.         traceline (src, src + direction*2048, FALSE, self);
  251.         if (trace_fraction != 1.0)
  252.             TraceAttack (4, direction);
  253.  
  254.         shotcount = shotcount - 1;
  255.     }
  256.     ApplyMultiDamage ();
  257. };
  258.  
  259. /*
  260. ================
  261. W_FireShotgun
  262. ================
  263. */
  264. void() W_FireShotgun =
  265. {
  266.     local vector dir;
  267.  
  268.     sound (self, CHAN_WEAPON, "weapons/guncock.wav", 1, ATTN_NORM);    
  269.  
  270.     self.punchangle_x = -2;
  271.     
  272.     self.currentammo = self.ammo_shells = self.ammo_shells - 1;
  273.     dir = aim (self, 100000);
  274.     FireBullets (6, dir, '0.04 0.04 0');
  275. };
  276.  
  277.  
  278. /*
  279. ================
  280. W_FireSuperShotgun
  281. ================
  282. */
  283. void() W_FireSuperShotgun =
  284. {
  285.     local vector dir;
  286.  
  287.     if (self.currentammo == 1)
  288.     {
  289.         W_FireShotgun ();
  290.         return;
  291.     }
  292.         
  293.     sound (self ,CHAN_WEAPON, "weapons/shotgn2.wav", 1, ATTN_NORM);    
  294.  
  295.     self.punchangle_x = -4;
  296.     
  297.     self.currentammo = self.ammo_shells = self.ammo_shells - 2;
  298.     dir = aim (self, 100000);
  299.     FireBullets (14, dir, '0.14 0.08 0');
  300. };
  301.  
  302.  
  303. /*
  304. ==============================================================================
  305.  
  306. ROCKETS
  307.  
  308. ==============================================================================
  309. */
  310.  
  311. void()    s_explode1    =    [0,        s_explode2] {};
  312. void()    s_explode2    =    [1,        s_explode3] {};
  313. void()    s_explode3    =    [2,        s_explode4] {};
  314. void()    s_explode4    =    [3,        s_explode5] {};
  315. void()    s_explode5    =    [4,        s_explode6] {};
  316. void()    s_explode6    =    [5,        SUB_Remove] {};
  317.  
  318. void() BecomeExplosion =
  319. {
  320.     self.movetype = MOVETYPE_NONE;
  321.     self.velocity = '0 0 0';
  322.     self.touch = SUB_Null;
  323.         setmodel (self, "progs/s_explod.spr");
  324.     self.solid = SOLID_NOT;
  325.     s_explode1 ();
  326. };
  327.  
  328. void() T_MissileTouch =
  329. {
  330.     local float    damg;
  331.  
  332.     if (other == self.owner)
  333.         return;        // don't explode on owner
  334.  
  335.     if (pointcontents(self.origin) == CONTENT_SKY)
  336.     {
  337.         remove(self);
  338.         return;
  339.     }
  340.  
  341.     damg = 100 + random()*20;
  342.     
  343.     if (other.health)
  344.     {
  345.         if (other.classname == "monster_shambler")
  346.             damg = damg * 0.5;    // mostly immune
  347.         T_Damage (other, self, self.owner, damg );
  348.     }
  349.  
  350.     // don't do radius damage to the other, because all the damage
  351.     // was done in the impact
  352.     T_RadiusDamage (self, self.owner, 120, other);
  353.  
  354.         sound (self, CHAN_WEAPON, "weapons/r_exp3.wav", 1, ATTN_NORM);
  355.     self.origin = self.origin - 8*normalize(self.velocity);
  356.  
  357. //        WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  358. //        WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  359. //        WriteCoord (MSG_BROADCAST, self.origin_x);
  360. //        WriteCoord (MSG_BROADCAST, self.origin_y);
  361. //        WriteCoord (MSG_BROADCAST, self.origin_z);
  362.  
  363.         BecomeExplosion ();
  364.  
  365. };
  366.  
  367.  
  368. /*
  369. ================
  370. W_FireRocket
  371. ================
  372. */
  373. void() W_FireRocket =
  374. {
  375.     local    entity missile, mpuff;
  376.     
  377.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  378.     
  379.     sound (self, CHAN_WEAPON, "weapons/sgun1.wav", 1, ATTN_NORM);
  380.  
  381.     self.punchangle_x = -2;
  382.  
  383.     missile = spawn ();
  384.     missile.owner = self;
  385.         missile.movetype = MOVETYPE_BOUNCE;
  386.     missile.solid = SOLID_BBOX;
  387.         
  388. // set missile speed    
  389.  
  390.     makevectors (self.v_angle);
  391.     missile.velocity = aim(self, 1000);
  392.     missile.velocity = missile.velocity * 1000;
  393.     missile.angles = vectoangles(missile.velocity);
  394.     
  395.     missile.touch = T_MissileTouch;
  396.     
  397. // set missile duration
  398.     missile.nextthink = time + 5;
  399.     missile.think = SUB_Remove;
  400.  
  401.     setmodel (missile, "progs/missile.mdl");
  402.     setsize (missile, '0 0 0', '0 0 0');        
  403.     setorigin (missile, self.origin + v_forward*8 + '0 0 16');
  404. };
  405.  
  406. /*
  407. ===============================================================================
  408.  
  409. LIGHTNING
  410.  
  411. ===============================================================================
  412. */
  413.  
  414. /*
  415. =================
  416. LightningDamage
  417. =================
  418. */
  419. void(vector p1, vector p2, entity from, float damage) LightningDamage =
  420. {
  421.     local entity        e1, e2;
  422.     local vector        f;
  423.     
  424.     f = p2 - p1;
  425.     normalize (f);
  426.     f_x = 0 - f_y;
  427.     f_y = f_x;
  428.     f_z = 0;
  429.     f = f*16;
  430.  
  431.     e1 = e2 = world;
  432.  
  433.     traceline (p1, p2, FALSE, self);
  434.     if (trace_ent.takedamage)
  435.     {
  436.         particle (trace_endpos, '0 0 100', 225, damage*4);
  437.         T_Damage (trace_ent, from, from, damage);
  438.         if (self.classname == "player")
  439.         {
  440.             if (other.classname == "player")
  441.                 trace_ent.velocity_z = trace_ent.velocity_z + 400;
  442.         }
  443.     }
  444.     e1 = trace_ent;
  445.  
  446.     traceline (p1 + f, p2 + f, FALSE, self);
  447.     if (trace_ent != e1 && trace_ent.takedamage)
  448.     {
  449.         particle (trace_endpos, '0 0 100', 225, damage*4);
  450.         T_Damage (trace_ent, from, from, damage);
  451.     }
  452.     e2 = trace_ent;
  453.  
  454.     traceline (p1 - f, p2 - f, FALSE, self);
  455.     if (trace_ent != e1 && trace_ent != e2 && trace_ent.takedamage)
  456.     {
  457.         particle (trace_endpos, '0 0 100', 225, damage*4);
  458.         T_Damage (trace_ent, from, from, damage);
  459.     }
  460. };
  461.  
  462.  
  463. void() W_FireLightning =
  464. {
  465.     local    vector        org;
  466.  
  467.     if (self.ammo_cells < 1)
  468.     {
  469.         self.weapon = W_BestWeapon ();
  470.         W_SetCurrentAmmo ();
  471.         return;
  472.     }
  473.  
  474. // explode if under water
  475.     if (self.waterlevel > 1)
  476.     {
  477.         T_RadiusDamage (self, self, 35*self.ammo_cells, world);
  478.         self.ammo_cells = 0;
  479.         W_SetCurrentAmmo ();
  480.         return;
  481.     }
  482.  
  483.     if (self.t_width < time)
  484.     {
  485.         sound (self, CHAN_WEAPON, "weapons/lhit.wav", 1, ATTN_NORM);
  486.         self.t_width = time + 0.6;
  487.     }
  488.     self.punchangle_x = -2;
  489.  
  490.     self.currentammo = self.ammo_cells = self.ammo_cells - 1;
  491.  
  492.     org = self.origin + '0 0 16';
  493.     
  494.     traceline (org, org + v_forward*600, TRUE, self);
  495.  
  496.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  497.     WriteByte (MSG_BROADCAST, TE_LIGHTNING2);
  498.     WriteEntity (MSG_BROADCAST, self);
  499.     WriteCoord (MSG_BROADCAST, org_x);
  500.     WriteCoord (MSG_BROADCAST, org_y);
  501.     WriteCoord (MSG_BROADCAST, org_z);
  502.     WriteCoord (MSG_BROADCAST, trace_endpos_x);
  503.     WriteCoord (MSG_BROADCAST, trace_endpos_y);
  504.     WriteCoord (MSG_BROADCAST, trace_endpos_z);
  505.  
  506.     LightningDamage (self.origin, trace_endpos + v_forward*4, self, 30);
  507. };
  508.  
  509.  
  510. //=============================================================================
  511.  
  512.  
  513. void() GrenadeExplode =
  514. {
  515.         sound (self, CHAN_WEAPON, "weapons/r_exp3.wav", 1, ATTN_NORM);
  516.         T_RadiusDamage (self, self.owner, 120, world);
  517.  
  518. //        WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  519. //        WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  520. //        WriteCoord (MSG_BROADCAST, self.origin_x);
  521. //        WriteCoord (MSG_BROADCAST, self.origin_y);
  522. //        WriteCoord (MSG_BROADCAST, self.origin_z);
  523.  
  524.     BecomeExplosion ();
  525. };
  526.  
  527. void() GrenadeTouch =
  528. {
  529.     if (other == self.owner)
  530.         return;        // don't explode on owner
  531.     if (other.takedamage == DAMAGE_AIM)
  532.     {
  533.         GrenadeExplode();
  534.         return;
  535.     }
  536.     sound (self, CHAN_WEAPON, "weapons/bounce.wav", 1, ATTN_NORM);    // bounce sound
  537.     if (self.velocity == '0 0 0')
  538.         self.avelocity = '0 0 0';
  539. };
  540.  
  541. /*
  542. ================
  543. W_FireGrenade
  544. ================
  545. */
  546. void() W_FireGrenade =
  547. {
  548.     local    entity missile, mpuff;
  549.     
  550.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  551.     
  552.     sound (self, CHAN_WEAPON, "weapons/grenade.wav", 1, ATTN_NORM);
  553.  
  554.     self.punchangle_x = -2;
  555.  
  556.     missile = spawn ();
  557.     missile.owner = self;
  558.     missile.movetype = MOVETYPE_BOUNCE;
  559.     missile.solid = SOLID_BBOX;
  560.     missile.classname = "grenade";
  561.         
  562. // set missile speed    
  563.  
  564.     makevectors (self.v_angle);
  565.  
  566.     if (self.v_angle_x)
  567.         missile.velocity = v_forward*600 + v_up * 200 + crandom()*v_right*10 + crandom()*v_up*10;
  568.     else
  569.     {
  570.         missile.velocity = aim(self, 10000);
  571.         missile.velocity = missile.velocity * 600;
  572.         missile.velocity_z = 200;
  573.     }
  574.  
  575.     missile.avelocity = '300 300 300';
  576.  
  577.     missile.angles = vectoangles(missile.velocity);
  578.     
  579.     missile.touch = GrenadeTouch;
  580.     
  581. // set missile duration
  582.     missile.nextthink = time + 2.5;
  583.     missile.think = GrenadeExplode;
  584.  
  585.     setmodel (missile, "progs/grenade.mdl");
  586.     setsize (missile, '0 0 0', '0 0 0');        
  587.     setorigin (missile, self.origin);
  588. };
  589.  
  590.  
  591. //=============================================================================
  592.  
  593. void() spike_touch;
  594. void() superspike_touch;
  595.  
  596.  
  597. /*
  598. ===============
  599. launch_spike
  600.  
  601. Used for both the player and the ogre
  602. ===============
  603. */
  604. void(vector org, vector dir) launch_spike =
  605. {
  606.     newmis = spawn ();
  607.     newmis.owner = self;
  608.     newmis.movetype = MOVETYPE_FLYMISSILE;
  609.     newmis.solid = SOLID_BBOX;
  610.  
  611.     newmis.angles = vectoangles(dir);
  612.     
  613.     newmis.touch = spike_touch;
  614.     newmis.classname = "spike";
  615.     newmis.think = SUB_Remove;
  616.     newmis.nextthink = time + 6;
  617.     setmodel (newmis, "progs/spike.mdl");
  618.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);        
  619.     setorigin (newmis, org);
  620.  
  621.     newmis.velocity = dir * 1000;
  622. };
  623.  
  624. void() W_FireSuperSpikes =
  625. {
  626.     local vector    dir;
  627.     local entity    old;
  628.     
  629.     sound (self, CHAN_WEAPON, "weapons/spike2.wav", 1, ATTN_NORM);
  630.     self.attack_finished = time + 0.2;
  631.     self.currentammo = self.ammo_nails = self.ammo_nails - 2;
  632.     dir = aim (self, 1000);
  633.     launch_spike (self.origin + '0 0 16', dir);
  634.     newmis.touch = superspike_touch;
  635.     setmodel (newmis, "progs/s_spike.mdl");
  636.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);        
  637.     self.punchangle_x = -2;
  638. };
  639.  
  640. void(float ox) W_FireSpikes =
  641. {
  642.     local vector    dir;
  643.     local entity    old;
  644.     
  645.     makevectors (self.v_angle);
  646.     
  647.     if (self.ammo_nails >= 2 && self.weapon == IT_SUPER_NAILGUN)
  648.     {
  649.         W_FireSuperSpikes ();
  650.         return;
  651.     }
  652.  
  653.     if (self.ammo_nails < 1)
  654.     {
  655.         self.weapon = W_BestWeapon ();
  656.         W_SetCurrentAmmo ();
  657.         return;
  658.     }
  659.  
  660.     sound (self, CHAN_WEAPON, "weapons/rocket1i.wav", 1, ATTN_NORM);
  661.     self.attack_finished = time + 0.2;
  662.     self.currentammo = self.ammo_nails = self.ammo_nails - 1;
  663.     dir = aim (self, 1000);
  664.     launch_spike (self.origin + '0 0 16' + v_right*ox, dir);
  665.  
  666.     self.punchangle_x = -2;
  667. };
  668.  
  669.  
  670.  
  671. .float hit_z;
  672. void() spike_touch =
  673. {
  674. local float rand;
  675.     if (other == self.owner)
  676.         return;
  677.  
  678.     if (other.solid == SOLID_TRIGGER)
  679.         return;    // trigger field, do nothing
  680.  
  681.     if (pointcontents(self.origin) == CONTENT_SKY)
  682.     {
  683.         remove(self);
  684.         return;
  685.     }
  686.     
  687. // hit something that bleeds
  688.     if (other.takedamage)
  689.     {
  690.         spawn_touchblood (9);
  691.         T_Damage (other, self, self.owner, 9);
  692.     }
  693.     else
  694.     {
  695.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  696.         
  697.         if (self.classname == "wizspike")
  698.             WriteByte (MSG_BROADCAST, TE_WIZSPIKE);
  699.         else if (self.classname == "knightspike")
  700.             WriteByte (MSG_BROADCAST, TE_KNIGHTSPIKE);
  701.         else
  702.             WriteByte (MSG_BROADCAST, TE_SPIKE);
  703.         WriteCoord (MSG_BROADCAST, self.origin_x);
  704.         WriteCoord (MSG_BROADCAST, self.origin_y);
  705.         WriteCoord (MSG_BROADCAST, self.origin_z);
  706.     }
  707.  
  708.     remove(self);
  709.  
  710. };
  711.  
  712. void() superspike_touch =
  713. {
  714. local float rand;
  715.     if (other == self.owner)
  716.         return;
  717.  
  718.     if (other.solid == SOLID_TRIGGER)
  719.         return;    // trigger field, do nothing
  720.  
  721.     if (pointcontents(self.origin) == CONTENT_SKY)
  722.     {
  723.         remove(self);
  724.         return;
  725.     }
  726.     
  727. // hit something that bleeds
  728.     if (other.takedamage)
  729.     {
  730.         spawn_touchblood (18);
  731.         T_Damage (other, self, self.owner, 18);
  732.     }
  733.     else
  734.     {
  735.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  736.         WriteByte (MSG_BROADCAST, TE_SUPERSPIKE);
  737.         WriteCoord (MSG_BROADCAST, self.origin_x);
  738.         WriteCoord (MSG_BROADCAST, self.origin_y);
  739.         WriteCoord (MSG_BROADCAST, self.origin_z);
  740.     }
  741.  
  742.     remove(self);
  743.  
  744. };
  745.  
  746.  
  747. /*
  748. ===============================================================================
  749.  
  750. PLAYER WEAPON USE
  751.  
  752. ===============================================================================
  753. */
  754.  
  755. void() W_SetCurrentAmmo =
  756. {
  757.     player_run ();        // get out of any weapon firing states
  758.  
  759.     self.items = self.items - ( self.items & (IT_SHELLS | IT_NAILS | IT_ROCKETS | IT_CELLS) );
  760.     
  761.     if (self.weapon == IT_AXE)
  762.     {
  763.         self.currentammo = 0;
  764.         self.weaponmodel = "progs/v_axe.mdl";
  765.         self.weaponframe = 0;
  766.     }
  767.     else if (self.weapon == IT_SHOTGUN)
  768.     {
  769.         self.currentammo = self.ammo_shells;
  770.         self.weaponmodel = "progs/v_shot.mdl";
  771.         self.weaponframe = 0;
  772.         self.items = self.items | IT_SHELLS;
  773.     }
  774.     else if (self.weapon == IT_SUPER_SHOTGUN)
  775.     {
  776.         self.currentammo = self.ammo_shells;
  777.         self.weaponmodel = "progs/v_shot2.mdl";
  778.         self.weaponframe = 0;
  779.         self.items = self.items | IT_SHELLS;
  780.     }
  781.     else if (self.weapon == IT_NAILGUN)
  782.     {
  783.         self.currentammo = self.ammo_nails;
  784.         self.weaponmodel = "progs/v_nail.mdl";
  785.         self.weaponframe = 0;
  786.         self.items = self.items | IT_NAILS;
  787.     }
  788.     else if (self.weapon == IT_SUPER_NAILGUN)
  789.     {
  790.         self.currentammo = self.ammo_nails;
  791.         self.weaponmodel = "progs/v_nail2.mdl";
  792.         self.weaponframe = 0;
  793.         self.items = self.items | IT_NAILS;
  794.     }
  795.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  796.     {
  797.         self.currentammo = self.ammo_rockets;
  798.         self.weaponmodel = "progs/v_rock.mdl";
  799.         self.weaponframe = 0;
  800.         self.items = self.items | IT_ROCKETS;
  801.     }
  802.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  803.     {
  804.         self.currentammo = self.ammo_rockets;
  805.         self.weaponmodel = "progs/v_rock2.mdl";
  806.         self.weaponframe = 0;
  807.         self.items = self.items | IT_ROCKETS;
  808.     }
  809.     else if (self.weapon == IT_LIGHTNING)
  810.     {
  811.         self.currentammo = self.ammo_cells;
  812.         self.weaponmodel = "progs/v_light.mdl";
  813.         self.weaponframe = 0;
  814.         self.items = self.items | IT_CELLS;
  815.     }
  816.     else
  817.     {
  818.         self.currentammo = 0;
  819.         self.weaponmodel = "";
  820.         self.weaponframe = 0;
  821.     }
  822. };
  823.  
  824. float() W_BestWeapon =
  825. {
  826.     local    float    it;
  827.     
  828.     it = self.items;
  829.  
  830.     if(self.ammo_cells >= 1 && (it & IT_LIGHTNING) )
  831.         return IT_LIGHTNING;
  832.     else if(self.ammo_nails >= 2 && (it & IT_SUPER_NAILGUN) )
  833.         return IT_SUPER_NAILGUN;
  834.     else if(self.ammo_shells >= 2 && (it & IT_SUPER_SHOTGUN) )
  835.         return IT_SUPER_SHOTGUN;
  836.     else if(self.ammo_nails >= 1 && (it & IT_NAILGUN) )
  837.         return IT_NAILGUN;
  838.     else if(self.ammo_shells >= 1 && (it & IT_SHOTGUN) )
  839.         return IT_SHOTGUN;
  840.         
  841. /*
  842.     if(self.ammo_rockets >= 1 && (it & IT_ROCKET_LAUNCHER) )
  843.         return IT_ROCKET_LAUNCHER;
  844.     else if(self.ammo_rockets >= 1 && (it & IT_GRENADE_LAUNCHER) )
  845.         return IT_GRENADE_LAUNCHER;
  846.  
  847. */
  848.  
  849.     return IT_AXE;
  850. };
  851.  
  852. float() W_CheckNoAmmo =
  853. {
  854.     if (self.currentammo > 0)
  855.         return TRUE;
  856.  
  857.     if (self.weapon == IT_AXE)
  858.         return TRUE;
  859.     
  860.     self.weapon = W_BestWeapon ();
  861.  
  862.     W_SetCurrentAmmo ();
  863.     
  864. // drop the weapon down
  865.     return FALSE;
  866. };
  867.  
  868. /*
  869. ============
  870. W_Attack
  871.  
  872. An attack impulse can be triggered now
  873. ============
  874. */
  875. void()    player_axe1;
  876. void()    player_axeb1;
  877. void()    player_axec1;
  878. void()    player_axed1;
  879. void()    player_shot1;
  880. void()    player_nail1;
  881. void()    player_light1;
  882. void()    player_rocket1;
  883.  
  884. void() W_Attack =
  885. {
  886.     local    float    r;
  887.  
  888.     if (!W_CheckNoAmmo ())
  889.         return;
  890.  
  891.     makevectors    (self.v_angle);            // calculate forward angle for velocity
  892.     self.show_hostile = time + 1;    // wake monsters up
  893.  
  894.     if (self.weapon == IT_AXE)
  895.     {
  896.         sound (self, CHAN_WEAPON, "weapons/ax1.wav", 1, ATTN_NORM);
  897.         r = random();
  898.         if (r < 0.25)
  899.             player_axe1 ();
  900.         else if (r<0.5)
  901.             player_axeb1 ();
  902.         else if (r<0.75)
  903.             player_axec1 ();
  904.         else
  905.             player_axed1 ();
  906.         self.attack_finished = time + 0.5;
  907.     }
  908.     else if (self.weapon == IT_SHOTGUN)
  909.     {
  910.         player_shot1 ();
  911.         W_FireShotgun ();
  912.         self.attack_finished = time + 0.5;
  913.     }
  914.     else if (self.weapon == IT_SUPER_SHOTGUN)
  915.     {
  916.         player_shot1 ();
  917.         W_FireSuperShotgun ();
  918.         self.attack_finished = time + 0.7;
  919.     }
  920.     else if (self.weapon == IT_NAILGUN)
  921.     {
  922.         player_nail1 ();
  923.     }
  924.     else if (self.weapon == IT_SUPER_NAILGUN)
  925.     {
  926.         player_nail1 ();
  927.     }
  928.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  929.     {
  930.         player_rocket1();
  931.         W_FireGrenade();
  932.         self.attack_finished = time + 0.6;
  933.     }
  934.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  935.     {
  936.         player_rocket1();
  937.         W_FireRocket();
  938.         self.attack_finished = time + 0.8;
  939.     }
  940.     else if (self.weapon == IT_LIGHTNING)
  941.     {
  942.         player_light1();
  943.         self.attack_finished = time + 0.1;
  944.         sound (self, CHAN_AUTO, "weapons/lstart.wav", 1, ATTN_NORM);
  945.     }
  946. };
  947.  
  948. /*
  949. ============
  950. W_ChangeWeapon
  951.  
  952. ============
  953. */
  954. void() W_ChangeWeapon =
  955. {
  956.     local    float    it, am, fl;
  957.     
  958.     it = self.items;
  959.     am = 0;
  960.     
  961.     if (self.impulse == 1)
  962.     {
  963.         fl = IT_AXE;
  964.     }
  965.     else if (self.impulse == 2)
  966.     {
  967.         fl = IT_SHOTGUN;
  968.         if (self.ammo_shells < 1)
  969.             am = 1;
  970.     }
  971.     else if (self.impulse == 3)
  972.     {
  973.         fl = IT_SUPER_SHOTGUN;
  974.         if (self.ammo_shells < 2)
  975.             am = 1;
  976.     }        
  977.     else if (self.impulse == 4)
  978.     {
  979.         fl = IT_NAILGUN;
  980.         if (self.ammo_nails < 1)
  981.             am = 1;
  982.     }
  983.     else if (self.impulse == 5)
  984.     {
  985.         fl = IT_SUPER_NAILGUN;
  986.         if (self.ammo_nails < 2)
  987.             am = 1;
  988.     }
  989.     else if (self.impulse == 6)
  990.     {
  991.         fl = IT_GRENADE_LAUNCHER;
  992.         if (self.ammo_rockets < 1)
  993.             am = 1;
  994.     }
  995.     else if (self.impulse == 7)
  996.     {
  997.         fl = IT_ROCKET_LAUNCHER;
  998.         if (self.ammo_rockets < 1)
  999.             am = 1;
  1000.     }
  1001.     else if (self.impulse == 8)
  1002.     {
  1003.         fl = IT_LIGHTNING;
  1004.         if (self.ammo_cells < 1)
  1005.             am = 1;
  1006.     }
  1007.  
  1008.     self.impulse = 0;
  1009.     
  1010.     if (!(self.items & fl))
  1011.     {    // don't have the weapon or the ammo
  1012.         sprint (self, "no weapon.\n");
  1013.         return;
  1014.     }
  1015.     
  1016.     if (am)
  1017.     {    // don't have the ammo
  1018.         sprint (self, "not enough ammo.\n");
  1019.         return;
  1020.     }
  1021.  
  1022. //
  1023. // set weapon, set ammo
  1024. //
  1025.     self.weapon = fl;        
  1026.     W_SetCurrentAmmo ();
  1027. };
  1028.  
  1029. /*
  1030. ============
  1031. CheatCommand
  1032. ============
  1033. */
  1034. void() CheatCommand =
  1035. {
  1036.         if (deathmatch || coop)
  1037.                 return;
  1038.  
  1039.     self.ammo_rockets = 100;
  1040.     self.ammo_nails = 200;
  1041.     self.ammo_shells = 100;
  1042.     self.items = self.items | 
  1043.         IT_AXE |
  1044.         IT_SHOTGUN |
  1045.         IT_SUPER_SHOTGUN |
  1046.         IT_NAILGUN |
  1047.         IT_SUPER_NAILGUN |
  1048.         IT_GRENADE_LAUNCHER |
  1049.         IT_ROCKET_LAUNCHER |
  1050.         IT_KEY1 | IT_KEY2;
  1051.  
  1052.     self.ammo_cells = 200;
  1053.     self.items = self.items | IT_LIGHTNING;
  1054.  
  1055.     self.weapon = IT_ROCKET_LAUNCHER;
  1056.     self.impulse = 0;
  1057.     W_SetCurrentAmmo ();
  1058. };
  1059.  
  1060. /*
  1061. ============
  1062. CycleWeaponCommand
  1063.  
  1064. Go to the next weapon with ammo
  1065. ============
  1066. */
  1067. void() CycleWeaponCommand =
  1068. {
  1069.     local    float    it, am;
  1070.     
  1071.     it = self.items;
  1072.     self.impulse = 0;
  1073.     
  1074.     while (1)
  1075.     {
  1076.         am = 0;
  1077.  
  1078.         if (self.weapon == IT_LIGHTNING)
  1079.         {
  1080.             self.weapon = IT_AXE;
  1081.         }
  1082.         else if (self.weapon == IT_AXE)
  1083.         {
  1084.             self.weapon = IT_SHOTGUN;
  1085.             if (self.ammo_shells < 1)
  1086.                 am = 1;
  1087.         }
  1088.         else if (self.weapon == IT_SHOTGUN)
  1089.         {
  1090.             self.weapon = IT_SUPER_SHOTGUN;
  1091.             if (self.ammo_shells < 2)
  1092.                 am = 1;
  1093.         }        
  1094.         else if (self.weapon == IT_SUPER_SHOTGUN)
  1095.         {
  1096.             self.weapon = IT_NAILGUN;
  1097.             if (self.ammo_nails < 1)
  1098.                 am = 1;
  1099.         }
  1100.         else if (self.weapon == IT_NAILGUN)
  1101.         {
  1102.             self.weapon = IT_SUPER_NAILGUN;
  1103.             if (self.ammo_nails < 2)
  1104.                 am = 1;
  1105.         }
  1106.         else if (self.weapon == IT_SUPER_NAILGUN)
  1107.         {
  1108.             self.weapon = IT_GRENADE_LAUNCHER;
  1109.             if (self.ammo_rockets < 1)
  1110.                 am = 1;
  1111.         }
  1112.         else if (self.weapon == IT_GRENADE_LAUNCHER)
  1113.         {
  1114.             self.weapon = IT_ROCKET_LAUNCHER;
  1115.             if (self.ammo_rockets < 1)
  1116.                 am = 1;
  1117.         }
  1118.         else if (self.weapon == IT_ROCKET_LAUNCHER)
  1119.         {
  1120.             self.weapon = IT_LIGHTNING;
  1121.             if (self.ammo_cells < 1)
  1122.                 am = 1;
  1123.         }
  1124.     
  1125.         if ( (self.items & self.weapon) && am == 0)
  1126.         {
  1127.             W_SetCurrentAmmo ();
  1128.             return;
  1129.         }
  1130.     }
  1131.  
  1132. };
  1133.  
  1134. /*
  1135. ============
  1136. ServerflagsCommand
  1137.  
  1138. Just for development
  1139. ============
  1140. */
  1141. void() ServerflagsCommand =
  1142. {
  1143.     serverflags = serverflags * 2 + 1;
  1144. };
  1145.  
  1146. void() QuadCheat =
  1147. {
  1148.         if (deathmatch || coop)
  1149.                 return;
  1150.     self.super_time = 1;
  1151.     self.super_damage_finished = time + 30;
  1152.     self.items = self.items | IT_QUAD;
  1153.     dprint ("quad cheat\n");
  1154. };
  1155.  
  1156. /*
  1157. ============
  1158. ImpulseCommands
  1159.  
  1160. ============
  1161. */
  1162. void() ImpulseCommands =
  1163. {
  1164.     if (self.impulse >= 1 && self.impulse <= 8)
  1165.         W_ChangeWeapon ();
  1166.  
  1167.     if (self.impulse == 9)
  1168.         CheatCommand ();
  1169.     if (self.impulse == 10)
  1170.         CycleWeaponCommand ();
  1171.     if (self.impulse == 11)
  1172.         ServerflagsCommand ();
  1173.  
  1174.     if (self.impulse == 255)
  1175.         QuadCheat ();
  1176.         
  1177.     self.impulse = 0;
  1178. };
  1179.  
  1180. /*
  1181. ============
  1182. W_WeaponFrame
  1183.  
  1184. Called every frame so impulse events can be handled as well as possible
  1185. ============
  1186. */
  1187. void() W_WeaponFrame =
  1188. {
  1189.     if (time < self.attack_finished)
  1190.         return;
  1191.  
  1192.     ImpulseCommands ();
  1193.     
  1194. // check for attack
  1195.     if (self.button0)
  1196.     {
  1197.         SuperDamageSound ();
  1198.         W_Attack ();
  1199.     }
  1200. };
  1201.  
  1202. /*
  1203. ========
  1204. SuperDamageSound
  1205.  
  1206. Plays sound if needed
  1207. ========
  1208. */
  1209. void() SuperDamageSound =
  1210. {
  1211.     if (self.super_damage_finished > time)
  1212.     {
  1213.         if (self.super_sound < time)
  1214.         {
  1215.             self.super_sound = time + 1;
  1216.             sound (self, CHAN_BODY, "items/damage3.wav", 1, ATTN_NORM);
  1217.         }
  1218.     }
  1219.     return;
  1220. };
  1221.  
  1222.  
  1223.